package org.fast.develop.logicflow.task;

import org.fast.develop.logicflow.builder.AbstractLogicFlowNodeBuilder;
import org.fast.develop.logicflow.core.LogicFlowConfiguration;
import org.fast.develop.logicflow.core.meta.shape.LogicFlowDefinition;
import org.fast.develop.logicflow.task.properties.BrmsJavaClassTaskProperties;

/**
 * @author 莫寅
 * @createTime 2022-11-25 15:51
 * @desc：
 */
public class BrmsJavaClassTaskBuilder extends AbstractLogicFlowNodeBuilder<BrmsJavaClassTaskBuilder, BrmsJavaClassTask>{

    private String className;
    private Class<BrmsTaskListener> taskClass;
    private String ruleId;

    public BrmsJavaClassTaskBuilder(LogicFlowDefinition logicFlowDefinition, LogicFlowConfiguration logicFlowConfiguration) {
        super(logicFlowDefinition, logicFlowConfiguration);

    }

    @Override
    protected Class<BrmsJavaClassTask> getElementClass() {
        return BrmsJavaClassTask.class;
    }


    public String getClassName() {
        return className;
    }

    public BrmsJavaClassTaskBuilder className(String className) {
        this.className = className;
        getProperties().setClassName(className);
        return this;
    }

    public String getRuleId() {
        return ruleId;
    }

    public BrmsJavaClassTaskBuilder ruleId(String ruleId) {
        this.ruleId = ruleId;
        getProperties().setRuleId(ruleId);
        return this;
    }

    public Class<BrmsTaskListener> getTaskClass() {
        return taskClass;
    }

    public BrmsJavaClassTaskBuilder taskClass(Class<BrmsTaskListener> taskClass) {
        this.taskClass = taskClass;
        getProperties().setClassName(taskClass.getName());
        return this;
    }

    private BrmsJavaClassTaskProperties getProperties(){
        if(getElement().getProperties() == null){
            getElement().setProperties(new BrmsJavaClassTaskProperties());
        }
        return getElement().getProperties();
    }
}
